#include "mainwindowimpl.h"
#include "sd.h"
#include <QLineEdit>
#include <QDebug>
#include <QAbstractItemModel>
#include <QStandardItemModel>
//


MainWindowImpl::MainWindowImpl( QWidget * parent, Qt::WFlags f) 
	: QMainWindow(parent, f), m(new QStandardItemModel(0, 1, this)){
	setupUi(this);
	ResTblVw->setModel(m);
}
//

void MainWindowImpl::on_StartActn_triggered(){
	QString text = TextLEdt->text();
	QString word;
	QList< int > res;
	for(int l = 15; l >= 1; --l )
		for(int f = 0; f < text.size() - l; ++f){
			word = text.mid(f, l);
			qDebug()<<word;
			res.clear();
			for(int i = 1; i < text.size();){
				i = text.indexOf(word, i);
				qDebug()<<i;
				if(i == -1)
					break;
				else
					res.append(i);
			}
			if(res.size() != 0){
				if(m->columnCount() < res.size() + 1)
					m->insertColumns(m->columnCount(), res.size() + 1 - m->columnCount());
				m->insertRow(m->rowCount());
				sd(m, m->rowCount() - 1, 0, word);
				for(int i = 0; i < res.size(); ++i){
					sd(m, m->rowCount() - 1, i + 1, res.at(i));
				}
			}
		}
}
